﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using BloomsburyBanHang.DAO;

namespace BloomsburyBanHang
{
    public partial class Admin_ThemTacGia : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Btn_Add_Click(object sender, EventArgs e)
        {
            string ten = txt_Ten.Text;
            string gioithieu = txt_GioiThieu.Text;
            string hinhanh = "";
            if (FileUpload1.HasFile)
            {
                try
                {
                    string filename = Path.GetFileName(FileUpload1.FileName);
                    FileUpload1.SaveAs(Server.MapPath("~/images/") + filename);
                    //Label2.Text = "Upload status: File uploaded!";
                    hinhanh = Server.MapPath("~/images/") + filename;
                   
                }
                catch (Exception ex)
                {
                    Label3.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
            int kq = TacGiaDAO.ThemTacGia(ten, hinhanh, gioithieu);
            if (kq == 1)
                this.Label3.Text = "Them tac gia thanh cong!!!";
            else
                this.Label3.Text = "Them tac gia that bai!!!";

        }
    }
}